package chapter7.集合;

import java.util.ArrayList;

public class sort2 {
    public static void main(String[] args) {
        //1.创建集合对象，用来存储数据
        ArrayList<chapter7.集合.sort13.Student> list = new ArrayList<>();

        //2.创建学生对象
        chapter7.集合.sort13.Student s1 = new chapter7.集合.sort13.Student("zhangsan",16);
        chapter7.集合.sort13.Student s2 = new chapter7.集合.sort13.Student("lisi",15);
        chapter7.集合.sort13.Student s3 = new chapter7.集合.sort13.Student("wangwu",18);

        //3.把学生对象添加到集合中
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //4.遍历
        for (int i = 0; i < list.size(); i++) {
            //i 依次表示集合中的每一个索引
            chapter7.集合.sort13.Student stu = list.get(i);
            System.out.println(stu.getName() + ", " + stu.getAge());
        }
    }
}
class Student {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
